var txt;
var userName = $('#userName').val();
var passWord = $('#passWord').val();
$.ajax({
    url: Feng.ctxPath + "/outpatientManagement/getLists",
    type: "post",
    data: {"userName": userName},
    success: function (data) {
        for (var i = 0; i < data.length; i++) {
            txt += '<option style="color: #666666;" value="' + data[i].simplename + '">' + data[i].simplename + '</option>';
        }
        document.getElementById('outpatientNamed').innerHTML = txt;
        var seleteooutpatientName = $('#outpatientNameValue').val();
        if (seleteooutpatientName != "") {
            $("#outpatientNamed option[value=" + seleteooutpatientName + "]").attr("selected", "selected");
        }
    },
    error: function (data) {
        alert('权限被限制，请联系管理员!');
        window.location.href = Feng.ctxPath + "/login";
    }
});

$("#outpatientNamed").change(function () {
    var outpatientName = $('#outpatientNamed').val();
    $.ajax({
        url: Feng.ctxPath + "/login",
        type: "post",
        data: {
            "username": userName,
            "outpatientName": outpatientName,
            "password": passWord
        },
        success: function (data) {
            window.location.href = Feng.ctxPath + "/index" ;
        },
        error: function (data) {
            alert('权限被限制，请联系管理员!');
            window.location.href = Feng.ctxPath + "/login";
        }
    });
});

var pageSize = 10;

function marketSearch() {
    var reach = $("#marketInputPublic").val().trim();
    if (reach == "" || reach == undefined || reach == null) {
        $("#marketSearchContent").hide().html("");
    } else {
        $.ajax({
            url: Feng.ctxPath + "/storeRecords/getReservationsByReach",
            type: "post",
            data: {
                reach: reach,
                pageStart: $("#pageStart").val(),
                pageSize: pageSize
            },
            success: function (datas) {
                var data = datas.customerInfoList;
                if (data.length > 0) {
                    var marketSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">找到' + datas.count + '个患者</div>';
                    marketSearchContent += '<div style="height: 323px;overflow: auto">';
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].status == "到店") {
                            marketSearchContent += '<div class="marketSearchShop" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                marketSearchContent += '<div><img src="/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            if (data[i].department == "直接上门") {
                                marketSearchContent += '<div>' +
                                    '<div><span class="marketCustomerName">' + data[i].customerName + '&nbsp;&nbsp;</span><span class="marketStatus" style="background: #5698c8;">' + data[i].status + '</span></div>' +
                                    '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                    '<div><span>' + data[i].arrivalStore + '&nbsp;</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '</span></div>' +
                                    '</div>' +
                                    '</div>';
                            } else {
                                marketSearchContent += '<div>' +
                                    '<div><span class="marketCustomerName">' + data[i].customerName + '&nbsp;&nbsp;</span><span class="marketStatus" style="background: #5698c8;">' + data[i].status + '</span><span class="marketStatus" style="background: #ff7e00;margin-left: 7px">S</span></div>' +
                                    '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                    '<div><span>' + data[i].arrivalStore + '&nbsp;</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '</span></div>' +
                                    '</div>' +
                                    '</div>';
                            }

                        } else if (data[i].status == "预约") {
                            marketSearchContent += '<div class="marketSearchMake" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    marketSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            if (data[i].department == "直接上门") {
                                marketSearchContent += '<div>' +
                                    '<div><span class="marketCustomerName">' + data[i].customerName + '&nbsp;&nbsp;</span><span class="marketStatus" style="background: #32b16c">' + data[i].status + '</span></div>' +
                                    '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                    '<div><span>' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '</span></div>' +
                                    '</div>' +
                                    '</div>';
                            } else {
                                marketSearchContent += '<div>' +
                                    '<div><span class="marketCustomerName">' + data[i].customerName + '&nbsp;&nbsp;</span><span class="marketStatus" style="background: #32b16c">' + data[i].status + '</span><span class="marketStatus" style="background: #ff7e00;margin-left: 7px">S</span></div>' +
                                    '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                    '<div><span>' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '</span></div>' +
                                    '</div>' +
                                    '</div>';
                            }

                        }
                    }
                    marketSearchContent += '<div style="text-align: center;padding:5px 10px;border-top: 1px solid #cccccc;font-size: 14px;"><a href="javascript:;" id="marketSearchNum">点击加载更多</a></div></div>';
                    $("#marketSearchContent").html(marketSearchContent).show()
                } else {
                    var marketSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">未搜索到患者</div>';
                    $("#marketSearchContent").html(marketSearchContent);
                }
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
}

function doctorTcSearch() {
    var reach = $("#doctorTcInputPublic").val().trim();
    if (reach == "" || reach == undefined || reach == null) {
        $("#doctorTcSearchContent").hide().html("");
    } else {
        $.ajax({
            url: Feng.ctxPath + "/customer/getCustomerByReach",
            type: "post",
            data: {
                reach: reach,
                pageStart: $("#pageStart").val(),
                pageSize: pageSize
            },
            success: function (datas) {
                var data = datas.customerInfoList;
                if (data.length > 0) {
                    var doctorTcSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">找到' + datas.count + '个患者</div>';
                    doctorTcSearchContent += '<div style="height: 323px;overflow: auto">';
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].accountArrears > 0) {
                            doctorTcSearchContent += '<div class="marketSearchShop" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            doctorTcSearchContent += '<div>' +
                                '<div><span class="marketCustomerName">' + data[i].customerName + '</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '&nbsp;</span><span class="marketStatus" style="background: red;border-radius: 50%;">欠</span></div>' +
                                '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                '<div><span>' + data[i].medicalRecordNumber + '</span><span>&nbsp;/&nbsp;' + data[i].arrivalStore + '</span></div>' +
                                '</div>' +
                                '</div>';
                        } else {
                            doctorTcSearchContent += '<div class="marketSearchShop" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            doctorTcSearchContent += '<div>' +
                                '<div><span class="marketCustomerName">' + data[i].customerName + '</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '</span><span class="marketStatus"></span></div>' +
                                '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                '<div><span>' + data[i].medicalRecordNumber + '</span><span>&nbsp;/&nbsp;' + data[i].arrivalStore + '</span></div>' +
                                '</div>' +
                                '</div>';
                        }
                    }
                    doctorTcSearchContent += '<div style="text-align: center;padding:5px 10px;border-top: 1px solid #cccccc;font-size: 14px;"><a href="javascript:;" id="doctorTcSearchNum">点击加载更多</a></div></div>';
                    $("#doctorTcSearchContent").html(doctorTcSearchContent).show()
                } else {
                    var doctorTcSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">未搜索到患者</div>';
                    $("#doctorTcSearchContent").html(doctorTcSearchContent);
                }
            },
            error: function (datas) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
}

function doctorTcSearchs() {
    var reach = $("#doctorTcInputPublics").val().trim();
    if (reach == "" || reach == undefined || reach == null) {
        $("#doctorTcSearchContents").hide().html("");
    } else {
        $.ajax({
            url: Feng.ctxPath + "/customer/getCustomerByReach",
            type: "post",
            data: {
                reach: reach,
                pageStart: $("#pageStart").val(),
                pageSize: pageSize
            },
            success: function (datas) {
                var data = datas.customerInfoList;
                if (data.length > 0) {
                    var doctorTcSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">找到' + datas.count + '个患者</div>';
                    doctorTcSearchContent += '<div style="height: 323px;overflow: auto">';
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].accountArrears > 0) {
                            doctorTcSearchContent += '<div class="marketSearchShop" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            doctorTcSearchContent += '<div>' +
                                '<div><span class="marketCustomerName">' + data[i].customerName + '</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '&nbsp;</span><span class="marketStatus" style="background: red;border-radius: 50%;">欠</span></div>' +
                                '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                '<div><span>' + data[i].medicalRecordNumber + '&nbsp;/&nbsp;</span><span>' + data[i].arrivalStore + '&nbsp;</span></div>' +
                                '</div>' +
                                '</div>';
                        } else {
                            doctorTcSearchContent += '<div class="marketSearchShop" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            doctorTcSearchContent += '<div>' +
                                '<div><span class="marketCustomerName">' + data[i].customerName + '</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '</span><span class="marketStatus"></span></div>' +
                                '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                '<div><span>' + data[i].medicalRecordNumber + '&nbsp;/&nbsp;</span><span>' + data[i].arrivalStore + '&nbsp;</span></div>' +
                                '</div>' +
                                '</div>';
                        }
                    }
                    doctorTcSearchContent += '<div style="text-align: center;padding:5px 10px;border-top: 1px solid #cccccc;font-size: 14px;"><a href="javascript:;" id="doctorTcSearchNums">点击加载更多</a></div></div>';
                    $("#doctorTcSearchContents").html(doctorTcSearchContent).show()
                } else {
                    var doctorTcSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">未搜索到患者</div>';
                    $("#doctorTcSearchContents").html(doctorTcSearchContent);
                }
            },
            error: function (datas) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
}

function doctorSearch() {
    var reach = $("#doctorInputPublic").val().trim();
    if (reach == "" || reach == undefined || reach == null) {
        $("#doctorSearchContent").hide().html("");
    } else {
        $.ajax({
            url: Feng.ctxPath + "/customer/getCustomerByReach",
            type: "post",
            data: {
                reach: reach,
                pageStart: $("#pageStart").val(),
                pageSize: pageSize
            },
            success: function (datas) {
                var data = datas.customerInfoList;
                if (data.length > 0) {
                    var doctorTcSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">找到' + datas.count + '个患者</div>';
                    doctorTcSearchContent += '<div style="height: 323px;overflow: auto">';
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].accountArrears > 0) {
                            doctorTcSearchContent += '<div class="marketSearchShop" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            doctorTcSearchContent += '<div>' +
                                '<div><span class="marketCustomerName">' + data[i].customerName + '</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '&nbsp;</span><span class="marketStatus" style="background: red;border-radius: 50%;">欠</span></div>' +
                                '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                '<div><span>' + data[i].medicalRecordNumber + '&nbsp;/&nbsp;</span><span>' + data[i].arrivalStore + '&nbsp;</span></div>' +
                                '</div>' +
                                '</div>';
                        } else {
                            doctorTcSearchContent += '<div class="marketSearchShop" id="' + data[i].id + '">';
                            if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                                doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            } else if (data[i].customerAge > 50) {
                                if (data[i].sex == "男") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                                } else if (data[i].sex == "女") {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                                } else {
                                    doctorTcSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                                }
                            }
                            doctorTcSearchContent += '<div>' +
                                '<div><span class="marketCustomerName">' + data[i].customerName + '</span><span>/&nbsp;' + data[i].customerAge + '岁&nbsp;</span><span>/&nbsp;' + data[i].sex + '</span><span class="marketStatus"></span></div>' +
                                '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].customerPhone2 + '</span></div>' +
                                '<div><span>' + data[i].medicalRecordNumber + '&nbsp;/&nbsp;</span><span>' + data[i].arrivalStore + '&nbsp;</span></div>' +
                                '</div>' +
                                '</div>';
                        }
                    }
                    doctorTcSearchContent += '<div style="text-align: center;padding:5px 10px;border-top: 1px solid #cccccc;font-size: 14px;"><a href="javascript:;" id="doctorSearchNum">点击加载更多</a></div></div>';
                    $("#doctorSearchContent").html(doctorTcSearchContent).show()
                } else {
                    var doctorTcSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">未搜索到患者</div>';
                    $("#doctorSearchContent").html(doctorTcSearchContent);
                }
            },
            error: function (datas) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
}

function foregroundSearch() {
    var reach = $("#foregroundInputPublic").val().trim();
    if (reach == "" || reach == undefined || reach == null) {
        $("#foregroundSearchContent").hide().html("");
    } else {
        $.ajax({
            url: Feng.ctxPath + "/customer/getCustomerByReach",
            type: "post",
            data: {
                reach: reach,
                pageStart: $("#pageStart").val(),
                pageSize: pageSize
            },
            success: function (datas) {
                var data = datas.customerInfoList;
                if (data.length > 0) {
                    var foregroundSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">找到' + datas.count + '个患者</div>';
                    foregroundSearchContent += '<div style="height: 323px;overflow: auto">';
                    for (var i = 0; i < data.length; i++) {
                        foregroundSearchContent += '<div class="marketSearchShop" id="' + data[i].reservationsId + '">';
                        if (data[i].customerAge == "" || data[i].customerAge == null || data[i].customerAge == "null") {
                            foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                        } else if (data[i].customerAge >= 0 && data[i].customerAge < 18) {
                            if (data[i].sex == "男") {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nan-child.png" alt="" width="50px;"></div>';
                            } else if (data[i].sex == "女") {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/nv-child.png" alt="" width="50px;"></div>';
                            } else {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            }
                        } else if (data[i].customerAge >= 18 && data[i].customerAge <= 50) {
                            if (data[i].sex == "男") {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-adult.png" alt="" width="50px;"></div>';
                            } else if (data[i].sex == "女") {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/lfemale-child.png" alt="" width="50px;"></div>';
                            } else {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            }
                        } else if (data[i].customerAge > 50) {
                            if (data[i].sex == "男") {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/male-old.png" alt="" width="50px;"></div>';
                            } else if (data[i].sex == "女") {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/female-old.png" alt="" width="50px;"></div>';
                            } else {
                                foregroundSearchContent += '<div><img src="' + Feng.ctxPath + '/static/img/unkown-sex.png" alt="" width="50px;"></div>';
                            }
                        }
                        foregroundSearchContent += '<div>' +
                            '<div><span class="marketCustomerName">' + data[i].customerName + '</span><span>&nbsp;&nbsp;' + data[i].sex + '</span><span style="margin-left: 10px;">' + data[i].customerAge + '岁</span></div>' +
                            '<div><span>' + data[i].customerPhone + '&nbsp;</span><span>/&nbsp;' + data[i].phoneSharShip + '</span></div>';
                        if (data[i].accountArrears > 0) {
                            foregroundSearchContent += '<div><span>' + data[i].medicalRecordNumber + '&nbsp;/&nbsp;</span><span>' + data[i].customerPhone2 + '&nbsp;</span><span class="marketStatus" style="background: red;border-radius: 50%">欠</span></div>';
                        } else {
                            foregroundSearchContent += '<div><span>' + data[i].medicalRecordNumber + '&nbsp;/&nbsp;</span><span>' + data[i].customerPhone2 + '&nbsp;</span></div>';
                        }
                        foregroundSearchContent += '<div style="position: absolute;right: 10px;top: 50%;transform: translateY(-50%);">' +
                            '<button type="button" class="btn foregroundBtn customerReconsulting">复诊</button>' +
                            '<button type="button" class="btn foregroundBtn insertReDiagnosis">重咨</button></div>' +
                            '</div>' +
                            '</div>';
                    }
                    foregroundSearchContent += '<div style="text-align: center;padding:5px 10px;border-top: 1px solid #cccccc;font-size: 14px;"><a href="javascript:;" id="foregroundSearchNum">点击加载更多</a></div></div>';
                    $("#foregroundSearchContent").html(foregroundSearchContent).show()
                } else {
                    var foregroundSearchContent = '<div style="font-size: 14px;padding: 4px 10px;border-bottom: 1px solid #dddddd;">未搜索到患者</div>';
                    $("#foregroundSearchContent").html(foregroundSearchContent);
                }
            },
            error: function (datas) {
                alert('没有权限，请联系管理员!');
            }
        });
    }
}

$(document).click(function () {
    $("#marketSearchContent,#doctorTcSearchContent,#doctorSearchContent,#doctorTcSearchContents,#foregroundSearchContent").hide();
    $("#pageStart").val("1")
});
$("#foregroundInputPublic").click(function (e) {
    e.stopPropagation();
    foregroundSearch();
});
$("#marketInputPublic").click(function (e) {
    e.stopPropagation();
    marketSearch();
});
$("#doctorTcInputPublic").click(function (e) {
    e.stopPropagation();
    doctorTcSearch();
});
$("#doctorTcInputPublics").click(function (e) {
    e.stopPropagation();
    doctorTcSearchs();
});
$("#doctorInputPublic").click(function (e) {
    e.stopPropagation();
    doctorSearch();
});
$(document).on('click', '#marketSearchNum', function (e) {
    e.stopPropagation();
    $("#pageStart").val(parseInt($("#pageStart").val()) + 1);
    marketSearch();
});
$(document).on('click', '#doctorTcSearchNum', function (e) {
    e.stopPropagation();
    $("#pageStart").val(parseInt($("#pageStart").val()) + 1);
    doctorTcSearch();
});
$(document).on('click', '#doctorTcSearchNums', function (e) {
    e.stopPropagation();
    $("#pageStart").val(parseInt($("#pageStart").val()) + 1);
    doctorTcSearchs();
});
$(document).on('click', '#doctorSearchNum', function (e) {
    e.stopPropagation();
    $("#pageStart").val(parseInt($("#pageStart").val()) + 1);
    doctorSearch();
});
$(document).on('click', '#foregroundSearchNum', function (e) {
    e.stopPropagation();
    $("#pageStart").val(parseInt($("#pageStart").val()) + 1);
    foregroundSearch();
})